/*
 * Project Beknyou
 * Copyright (c) 2010-2011 Saint Paul College, All Rights Reserved
 * Redistributions in source code form must reproduce the above
 * Copyright and this condition.
 * The contents of this file are subject to the GNU General Public
 * License, Version 2 (the "License"); you may not use this file
 * except in compliance with the License. A copy of the License is
 * available at http://www.opensource.org/licenses/gpl-license.php.
 */
package com.benkyou.server;

import com.benkyou.server.GameServer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Austin Allman
 */
public class ServerConsole implements Runnable{
        private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
       private String consoleInput = "";
       private GameServer gameServer;
       public ServerConsole(GameServer gameServer){
           this.gameServer = gameServer;           
       }

    public void run() {
       while(!Thread.currentThread().isInterrupted()) {
    System.out.print("Benkyou >");
            try {
                consoleInput = in.readLine();
            } catch (IOException ex) {
                Logger.getLogger(ServerConsole.class.getName()).log(Level.SEVERE, null, ex);
            }
    proccessCommands(consoleInput);
}
    }
     public void proccessCommands(String command){
       if(command.equalsIgnoreCase("webcam status")){
          System.out.println("Webcam server is up! reading image from:\n" + gameServer.getWebcamURL()  );
       }
       else if(command.equalsIgnoreCase("help")){
           System.out.println("\n########################################################");
           System.out.println("Benkyou commands list:\nhelp\t\tDisplays this help screen\nexit\t\tShuts down the server\nwebcam status\t shows the current status of the webcam");
           System.out.println("start webcam\t starts the webcam server");
           System.out.println("stop webcam \t shuts down the webcam server");
           System.out.println("clear \t clears the console text");
           System.out.println("\n########################################################");
       }
       else if(command.equalsIgnoreCase("start webcam")){
              System.out.println("Starting webcam...\nWebcam location: "+ gameServer.getWebcamURL() + "\nWebcam server started.");   
       }else if(command.equalsIgnoreCase("stop webcam")){
          
               System.out.println("webcam server stoped");
       }else if(command.equalsIgnoreCase("exit")){
           gameServer.destroy();
           System.out.println("Server shuting down....");
       }else if(command.equalsIgnoreCase("clear")){
        System.out.print((char)27 + "[2J");      
       }
   }    
    
}
